# data file for the Fltk User Interface Designer (fluid)
version 1.0110 
header_name {.h} 
code_name {.cc}
decl {//Copyright (c) 2002-2009 Nasca Octavian Paul} {} 

decl {//License: GNU GPL version 2 or later} {} 

decl {\#include <stdlib.h>} {public
} 

decl {\#include <stdio.h>} {public
} 

decl {\#include <string.h>} {public
} 

decl {\#include "WidgetPDial.h"} {public
} 

decl {\#include "ADnoteUI.h"} {public
} 

decl {\#include "SUBnoteUI.h"} {public
} 

decl {\#include "EffUI.h"} {public
} 

decl {\#include "VirKeyboard.h"} {public
} 

decl {\#include "ConfigUI.h"} {public
} 

decl {\#include "BankUI.h"} {public
} 

decl {\#include "PartUI.h"} {public
} 

decl {\#include "MicrotonalUI.h"} {public
} 

decl {\#include "PresetsUI.h"} {public
} 

decl {\#include "NioUI.h"} {public global
} 

decl {\#include "../Misc/Master.h"} {public
} 

decl {\#include "../Misc/Part.h"} {public
} 

decl {\#include "../Misc/Util.h"} {public
} 

decl {\#include "common.H"} {public
} 

decl {\#if USE_NSM
\#include "NSM.H"
extern NSM_Client *nsm;
\#endif} {public
} 

decl {\#include "../globals.h"} {public
} 

class VUMeter {: {public Fl_Box}
} {
  Function {VUMeter(int x,int y, int w, int h, const char *label=0):Fl_Box(x,y,w,h,label)} {} {
    code {master=NULL;
npart=-1;} {}
  }
  Function {init(Master *master_,int part_)} {} {
    code {//the "part_" parameters sets the part (if it is >=0), else it sets the master
master=master_;
label(NULL);
npart=part_;
olddbl=0.0;
olddbr=0.0;
oldrmsdbl=0.0;
oldrmsdbr=0.0;} {}
  }
  Function {draw_master()} {} {
    code {\#define MIN_DB (-48)

int ox=x(); int oy=y(); int lx=w(); int ly=h();

vuData data = master->getVuData();

//pthread_mutex_lock(&master->mutex);
float dbl=rap2dB(data.outpeakl);
float dbr=rap2dB(data.outpeakr);
float rmsdbl=rap2dB(data.rmspeakl);
float rmsdbr=rap2dB(data.rmspeakr);
float maxdbl=rap2dB(data.maxoutpeakl);
float maxdbr=rap2dB(data.maxoutpeakr);
int clipped=data.clipped;
//pthread_mutex_unlock(&master->mutex);

dbl=(MIN_DB-dbl)/MIN_DB; 
if (dbl<0.0) dbl=0.0;
  else if (dbl>1.0)dbl=1.0;

dbr=(MIN_DB-dbr)/MIN_DB; 
if (dbr<0.0) dbr=0.0;
  else if (dbr>1.0) dbr=1.0; 

dbl=dbl*0.4+olddbl*0.6;
dbr=dbr*0.4+olddbr*0.6;

if ( damage() & FL_DAMAGE_USER1 )
{
        if ( olddbl == dbl && olddbr == dbr )
             return;
}

olddbl=dbl;
olddbr=dbr;

\#define VULENX (lx-35)
\#define VULENY (ly/2-3)

dbl*=VULENX;dbr*=VULENX;

int idbl=(int) dbl;
int idbr=(int) dbr;

//compute RMS - start
rmsdbl=(MIN_DB-rmsdbl)/MIN_DB; 
if (rmsdbl<0.0) rmsdbl=0.0;
  else if (rmsdbl>1.0) rmsdbl=1.0;

rmsdbr=(MIN_DB-rmsdbr)/MIN_DB; 
if (rmsdbr<0.0) rmsdbr=0.0;
  else if (rmsdbr>1.0) rmsdbr=1.0; 

rmsdbl=rmsdbl*0.4+oldrmsdbl*0.6;
rmsdbr=rmsdbr*0.4+oldrmsdbr*0.6;

oldrmsdbl=rmsdbl;
oldrmsdbr=rmsdbr;


rmsdbl*=VULENX;rmsdbr*=VULENX;

int irmsdbl=(int) rmsdbl;
int irmsdbr=(int) rmsdbr;
//compute RMS - end



//draw the vu-meter lines
//db
fl_rectf(ox,oy,idbr,VULENY,0,200,255);
fl_rectf(ox,oy+ly/2,idbl,VULENY,0,200,255);
//black
fl_rectf(ox+idbr,oy,VULENX-idbr,VULENY,0,0,0);
fl_rectf(ox+idbl,oy+ly/2,VULENX-idbl,VULENY,0,0,0);

//draw the scales
float  tmp=VULENX*1.0/MIN_DB;
for (int i=1;i<1-MIN_DB;i++){
   int tx=VULENX+(int) (tmp*i);
   fl_rectf(ox+tx,oy,1,VULENY+ly/2,0,160,200);
   if (i%5==0) fl_rectf(ox+tx,oy,1,VULENY+ly/2,0,230,240);
   if (i%10==0) fl_rectf(ox+tx-1,oy,2,VULENY+ly/2,0,225,255);
};

//rms
if (irmsdbr>2) fl_rectf(ox+irmsdbr-1,oy,3,VULENY,255,255,0);
if (irmsdbl>2) fl_rectf(ox+irmsdbl-1,oy+ly/2,3,VULENY,255,255,0);


//draw the red box if clipping has occured
if (clipped==0) fl_rectf(ox+VULENX+2,oy+1,lx-VULENX-3,ly-4,0,0,10);
           else fl_rectf(ox+VULENX+2,oy+1,lx-VULENX-3,ly-4,250,10,10);

//draw the maxdB 
fl_font(FL_HELVETICA|FL_BOLD,10);
fl_color(255,255,255);
char tmpstr[10];
if ((maxdbl>MIN_DB-20)){
  snprintf((char *)&tmpstr,10,"%ddB",(int)maxdbr);
  fl_draw(tmpstr,ox+VULENX+1,oy+1,lx-VULENX-1,VULENY,FL_ALIGN_RIGHT,NULL,0);
};
if ((maxdbr>MIN_DB-20)){
  snprintf((char *)&tmpstr,10,"%ddB",(int)maxdbl);
  fl_draw(tmpstr,ox+VULENX+1,oy+ly/2+1,lx-VULENX-1,VULENY,FL_ALIGN_RIGHT,NULL,0);
};} {}
  }
  Function {draw_part()} {} {
    code {\#define MIN_DB (-48)
int ox=x(); int oy=y(); int lx=w(); int ly=h();

if (!active_r()){
  pthread_mutex_lock(&master->vumutex);
   int fakedb=master->fakepeakpart[npart];
  pthread_mutex_unlock(&master->vumutex);
  fl_rectf(ox,oy,lx,ly,140,140,140);
  if (fakedb>0){
    fakedb=(int)(fakedb/255.0*ly)+4;
    fl_rectf(ox+2,oy+ly-fakedb,lx-4,fakedb,0,0,0);
  };
  
  return;
};

//draw the vu lines
pthread_mutex_lock(&master->vumutex);
 float db=rap2dB(master->vuoutpeakpart[npart]);
pthread_mutex_unlock(&master->vumutex);

db=(MIN_DB-db)/MIN_DB; 
if (db<0.0) db=0.0;
  else if (db>1.0) db=1.0;

db*=ly-2;

int idb=(int) db;

fl_rectf(ox,oy+ly-idb,lx,idb,0,200,255);
fl_rectf(ox,oy,lx,ly-idb,0,0,0);


//draw the scales
float  tmp=ly*1.0/MIN_DB;
 for (int i=1;i<1-MIN_DB;i++){
    int ty=ly+(int) (tmp*i);
    if (i%5==0) fl_rectf(ox,oy+ly-ty,lx,1,0,160,200);
    if (i%10==0) fl_rectf(ox,oy+ly-ty,lx,1,0,230,240);
};} {}
  }
  Function {draw()} {} {
    code {if (npart>=0) draw_part();
   else draw_master();} {}
  }
  Function {tickdraw(VUMeter *o)} {return_type {static void}
  } {
    code {o->damage(FL_DAMAGE_USER1);} {}
  }
  Function {tick(void *v)} {return_type {static void}
  } {
    code {tickdraw((VUMeter *) v);
          Fl::repeat_timeout(1.0/18.0,tick,v);//18 fps} {}
  }
  Function {handle(int event)} {return_type int
  } {
    code {switch(event){
   case FL_SHOW:
             Fl::add_timeout(1.0/18.0,tick,this);
             break;
   case FL_HIDE:
             Fl::remove_timeout(tick,this);
             break;
   case FL_PUSH:
             if (npart>=0) break;
             pthread_mutex_lock(&master->mutex);
             master->vuresetpeaks();
             pthread_mutex_unlock(&master->mutex);
             break;
};
return(1);} {}
  }
  decl {Master *master;} {}
  decl {int npart;} {}
  decl {float olddbl,olddbr;} {}
  decl {float oldrmsdbl,oldrmsdbr;} {}
} 

class SysEffSend {open : {public WidgetPDial}
} {
  Function {SysEffSend(int x,int y, int w, int h, const char *label=0):WidgetPDial(x,y,w,h,label)} {} {
    code {master=NULL;
neff1=0;
neff2=0;} {}
  }
  Function {init(Master *master_,int neff1_,int neff2_)} {} {
    code {neff1=neff1_;
neff2=neff2_;
master=master_;
minimum(0);
maximum(127);
step(1);
labelfont(1);
labelsize(10);
align(FL_ALIGN_TOP);

value(master->Psysefxsend[neff1][neff2]);
char tmp[20];snprintf(tmp,20,"%d->%d",neff1+1,neff2+1);
this->copy_label(tmp);} {}
  }
  Function {~SysEffSend()} {} {
    code {hide();} {}
  }
  Function {handle(int event)} {return_type int
  } {
    code {if ((event==FL_PUSH) || (event==FL_DRAG)){
   master->setPsysefxsend(neff1,neff2,(int) value());
};

return(WidgetPDial::handle(event));} {}
  }
  decl {Master *master;} {}
  decl {int neff1;} {}
  decl {int neff2;} {}
} 

class Panellistitem {open : {public Fl_Group}
} {
  Function {make_window()} {open private
  } {
    Fl_Window panellistitem {open
      private xywh {608 711 100 260} type Double box FLAT_BOX
      class Fl_Group visible
    } {
      Fl_Group panellistitemgroup {open
        private xywh {0 20 70 240} box UP_FRAME
        code0 {if (master->part[npart]->Penabled==0) o->deactivate();}
        code1 {set_module_parameters( o );}
      } {
        Fl_Group {} {
          xywh {45 65 15 110} box ENGRAVED_FRAME
        } {
          Fl_Box {} {
            label {V U}
            xywh {45 65 15 110} box FLAT_BOX color 0 selection_color 75 labelcolor 55 align 128
            code0 {o->init(master,npart);}
            class VUMeter
          }
        }
        Fl_Button partname {
          label {  }
          callback {if ((int)bankui->cbwig->value()!=(npart+1)){
   bankui->cbwig->value(npart+1);
   bankui->cbwig->do_callback();
};
bankui->show();}
          xywh {5 27 60 30} box THIN_DOWN_BOX down_box FLAT_BOX labelfont 1 labelsize 10 align 208
        }
        Fl_Slider partvolume {
          callback {master->part[npart]->setPvolume((int) o->value());}
          xywh {10 65 30 110} type {Vert Knob} box FLAT_BOX minimum 127 maximum 0 step 1 value 127
          code0 {o->value(master->part[npart]->Pvolume);}
        }
        Fl_Dial partpanning {
          callback {master->part[npart]->setPpanning((int) o->value());}
          xywh {20 180 30 30} maximum 127 step 1
          code0 {o->value(master->part[npart]->Ppanning);}
          class WidgetPDial
        }
        Fl_Button {} {
          label edit
          callback {if ((int)bankui->cbwig->value()!=(npart+1)){
   bankui->cbwig->value(npart+1);
   bankui->cbwig->do_callback();
};}
          xywh {15 235 40 20} labelsize 10
        }
        Fl_Choice partrcv {
          callback {master->part[npart]->Prcvchn=(int) o->value();}
          tooltip {receive from Midi channel} xywh {10 213 50 15} down_box BORDER_BOX labelsize 10 align 5 textfont 1 textsize 10
          code0 {char nrstr[10]; for(int i=0;i<NUM_MIDI_CHANNELS;i++){sprintf(nrstr,"Ch%d",i+1);if (i!=9) o->add(nrstr); else o->add("Dr10");};}
          code1 {o->value(master->part[npart]->Prcvchn);}
        } {}
      }
      Fl_Check_Button partenabled {
        label 01
        callback {pthread_mutex_lock(&master->mutex);
 master->partonoff(npart,(int) o->value());
pthread_mutex_unlock(&master->mutex);

if ((int) o->value()==0) panellistitemgroup->deactivate();
  else {
    panellistitemgroup->activate();
    if ((int)bankui->cbwig->value()!=(npart+1)){
       bankui->cbwig->value(npart+1);
       bankui->cbwig->do_callback();
    };
};

o->redraw();}
        private xywh {5 0 45 20} down_box DOWN_BOX labeltype EMBOSSED_LABEL labelfont 1 labelsize 13 align 24
        code0 {char tmp[10];snprintf(tmp,10,"%d",npart+1);o->copy_label(tmp);}
        code1 {o->value(master->part[npart]->Penabled);}
      }
    }
  }
  Function {Panellistitem(int x,int y, int w, int h, const char *label=0):Fl_Group(x,y,w,h,label)} {} {
    code {npart=0;
master=NULL;
bankui=NULL;} {}
  }
  Function {init(Master *master_, int npart_,BankUI *bankui_)} {} {
    code {npart=npart_;
master=master_;
bankui=bankui_;

make_window();
panellistitem->show();
end();} {}
  }
  Function {refresh()} {} {
    code {partenabled->value(master->part[npart]->Penabled);
if (master->part[npart]->Penabled!=0) panellistitemgroup->activate();
     else panellistitemgroup->deactivate();

partvolume->value(master->part[npart]->Pvolume);
partpanning->value(master->part[npart]->Ppanning);
partrcv->value(master->part[npart]->Prcvchn);

partname->label((char *)master->part[npart]->Pname);

if ((int)bankui->cbwig->value()!=(npart+1))
   panellistitemgroup->color(fl_rgb_color(160,160,160));
else 
   panellistitemgroup->color(fl_rgb_color(50,190,240));

panellistitemgroup->redraw();} {}
  }
  Function {~Panellistitem()} {} {
    code {panellistitem->hide();
//delete(panellistitem);} {}
  }
  decl {int npart;} {}
  decl {Master *master;} {}
  decl {BankUI *bankui;} {}
} 

class MasterUI {open
} {
  Function {make_window()} {open
  } {
    Fl_Window masterwindow {
      label zynaddsubfx
      callback {if ((
\#ifdef PLUGINVERSION
1
\#elif USE_NSM 
(nsm && nsm->is_active())
\#else
0
\#endif
 || fl_choice("Exit and leave the unsaved data?","No","Yes",NULL))) {
    config.save();
    *exitprogram=1;
};
} open
      xywh {80 370 390 525} type Double xclass zynaddsubfx visible
    } {
      Fl_Menu_Bar mastermenu {
        xywh {-5 0 690 25}
      } {
        Submenu {} {
          label {&File}
          xywh {0 0 100 20}
        } {
          MenuItem {} {
            label {&New (erase all)...}
            callback {do_new_master();}
            xywh {20 20 100 20}
          }
          MenuItem {} {
            label {&Open Parameters...}
            callback {\#if USE_NSM
            if ( nsm && nsm->is_active() )
            {
                do_load_master();
                do_save_master( nsm->project_filename );
            }
            else
\#endif
            {
                do_load_master();
            }}
            xywh {20 20 100 20}
          }
          MenuItem {} {
            label {&Save All Parameters...}
            callback {\#if USE_NSM
            if ( nsm && nsm->is_active() )
            {
                do_save_master( nsm->project_filename );
            }
            else
\#endif
            {
                 do_save_master();
            }}
            xywh {10 10 100 20} divider
          }
          MenuItem {} {
            label {&Load Scale Settings...}
            callback {char *filename;
filename=fl_file_chooser("Open:","({*.xsz})",NULL,0);
if (filename==NULL) return;

pthread_mutex_lock(&master->mutex);
  //clear all parameters
  master->microtonal.defaults();

  //load the data
  int result=master->microtonal.loadXML(filename);
pthread_mutex_unlock(&master->mutex);


 delete microtonalui;  
 microtonalui=new MicrotonalUI(&master->microtonal);

if (result==-10) fl_alert("Error: Could not load the file\\nbecause it is not a scale file.");
      else if (result<0) fl_alert("Error: Could not load the file.");}
            xywh {35 35 100 20}
          }
          MenuItem {} {
            label {Save Sc&ale Settings ..}
            callback {char *filename;
int result=0;

filename=fl_file_chooser("Save:","({*.xsz})",NULL,0);
if (filename==NULL) return;
filename=fl_filename_setext(filename,".xsz");

result=fileexists(filename);
if (result) {
    result=0;
   if (!fl_choice("The file exists. \\nOverwrite it?","No","Yes",NULL)) return;
       
};


pthread_mutex_lock(&master->mutex);
result=master->microtonal.saveXML(filename);
pthread_mutex_unlock(&master->mutex);

if (result<0) fl_alert("Error: Could not save the file.");


updatepanel();}
            xywh {25 25 100 20}
          }
          MenuItem {} {
            label {Show Scale Settings...}
            callback {microtonalui->show();}
            xywh {0 0 100 20} divider
          }
          MenuItem {} {
            label {&Settings...}
            callback {configui->show();}
            xywh {25 25 100 20}
          }
          MenuItem {} {
            label {N&io Settings}
            callback {nioui.refresh();
nioui.show();}
            xywh {0 0 36 21} divider
          }
          MenuItem {} {
            label {&Copyright...}
            callback {aboutwindow->show();}
            xywh {15 15 100 20} divider
          }
          MenuItem {} {
            label {E&xit}
            callback {masterwindow->do_callback();}
            xywh {10 10 100 20}
          }
        }
        Submenu {} {
          label {&Instrument}
          xywh {10 10 100 20}
        } {
          MenuItem {} {
            label {&Clear Instrument...}
            callback {if (fl_choice("Clear instrument's parameters ?","No","Yes",NULL)){
//       int npart=(int)npartcounter->value()-1;
       pthread_mutex_lock(&master->mutex);
       master->part[npart]->defaultsinstrument();
       pthread_mutex_unlock(&master->mutex);

       npartcounter->do_callback();
};

updatepanel();}
            xywh {35 35 100 20}
          }
          MenuItem {} {
            label {&Open Instrument...}
            callback {const char *filename;
filename=fl_file_chooser("Load:","({*.xiz})",NULL,0);
if (filename==NULL) return;


pthread_mutex_lock(&master->mutex);
//  int npart=(int)npartcounter->value()-1;

  //clear all instrument parameters, first
  master->part[npart]->defaultsinstrument();

  //load the instr. parameters
  int result=master->part[npart]->loadXMLinstrument(filename);

pthread_mutex_unlock(&master->mutex);
master->part[npart]->applyparameters();

npartcounter->do_callback();
updatepanel();

if (result==-10) fl_alert("Error: Could not load the file\\nbecause it is not an instrument file.");
      else if (result<0) fl_alert("Error: Could not load the file.");}
            xywh {30 30 100 20}
          }
          MenuItem {} {
            label {&Save Instrument ...}
            callback {char *filename;

filename=fl_file_chooser("Save:","({*.xiz})",NULL,0);
if (filename==NULL) return;
filename=fl_filename_setext(filename,".xiz");

int result=fileexists(filename);
if (result) {
    result=0;
   if (!fl_choice("The file exists. \\nOverwrite it?","No","Yes",NULL)) return;
       
};


pthread_mutex_lock(&master->mutex);
result=master->part[npart]->saveXML(filename);
pthread_mutex_unlock(&master->mutex);

if (result<0) fl_alert("Error: Could not save the file.");

updatepanel();}
            xywh {20 20 100 20} divider
          }
          MenuItem {} {
            label {Show Instrument &Bank...}
            callback {bankui->show();}
            xywh {0 0 100 20} divider
          }
          MenuItem {} {
            label {&Virtual Keyboard...}
            callback {virkeyboard->show();}
            xywh {10 10 100 20}
          }
        }
        Submenu recordmenu {
          label {&Record}
          xywh {0 0 100 20}
        } {
          MenuItem {} {
            label {&Choose WAV file...}
            callback {char *filename;
recordbutton->deactivate();
pausebutton->deactivate();
pauselabel->deactivate();
stopbutton->deactivate();
filename=fl_file_chooser("Record to audio file:","(*.wav)",NULL,0);
if (filename==NULL) return;
fl_filename_setext(filename,".wav");

int result=master->HDDRecorder.preparefile(filename,0);
if (result==1) {
    result=0;
   if (fl_choice("The file exists. \\nOverwrite it?","No","Yes",NULL))
       master->HDDRecorder.preparefile(filename,1);
};
if (result==0) recordbutton->activate();

if (result!=0) fl_alert("Error: Could not save the file.");}
            xywh {0 0 100 20}
          }
        }
        Submenu {} {
          label Misc
          xywh {10 10 100 20}
        } {
          MenuItem {} {
            label {Switch User Interface Mode}
            callback {if (fl_choice("Switch the User Interface to Beginner mode ?","No","Yes",NULL)){
	masterwindow->hide();
	refresh_master_ui();
	simplemasterwindow->show();
	config.cfg.UserInterfaceMode=2;
};}
            xywh {10 10 100 20}
          }
        }
      }
      Fl_Dial mastervolumedial {
        label {Master Volume}
        callback {master->setPvolume((int) o->value());}
        tooltip {Master Volume} xywh {15 32 55 55} box ROUND_UP_BOX labelsize 9 align 130 maximum 127 step 1
        code0 {o->value(master->Pvolume);}
        class WidgetPDial
      }
      Fl_Counter masterkeyshiftcounter {
        label {Master KeyShift}
        callback {master->setPkeyshift((int) o->value()+64);}
        xywh {150 97 120 23} type Simple labelsize 9 minimum -64 maximum 64 step 1
        code0 {o->lstep(12);}
        code1 {o->value(master->Pkeyshift-64);}
      }
      Fl_Button {} {
        label {Panic!}
        callback {virkeyboard->relaseallkeys();
pthread_mutex_lock(&master->mutex);
master->shutup=1;
pthread_mutex_unlock(&master->mutex);}
        xywh {280 29 105 53} color 90 labelfont 1
      }
      Fl_Group partuigroup {open
        xywh {0 310 390 205}
      } {
        Fl_Group partui {open selected
          xywh {0 310 383 175}
          code0 {o->init(master->part[0],master,0,bankui);}
          code1 {o->show();}
          class PartUI
        } {}
      }
      Fl_Tabs {} {open
        xywh {0 145 390 165} box UP_FRAME
      } {
        Fl_Group {} {
          label {System Effects} open
          xywh {0 162 390 145} labelsize 15 align 9
        } {
          Fl_Counter syseffnocounter {
            label {Sys.Effect No.}
            callback {nsyseff=(int) o->value()-1;
sysefftype->value(master->sysefx[nsyseff]->geteffect());
syseffectui->refresh(master->sysefx[nsyseff]);}
            xywh {5 181 80 22} type Simple labelfont 1 labelsize 10 align 1 minimum 0 maximum 127 step 1 value 1 textfont 1
            code0 {o->bounds(1,NUM_SYS_EFX);}
            code1 {o->value(nsyseff+1);}
          }
          Fl_Choice sysefftype {
            label EffType
            callback {pthread_mutex_lock(&master->mutex);
master->sysefx[nsyseff]->changeeffect((int) o->value());
pthread_mutex_unlock(&master->mutex);
syseffectui->refresh(master->sysefx[nsyseff]);}
            xywh {285 176 100 22} down_box BORDER_BOX labelsize 10
            code0 {o->value(master->sysefx[nsyseff]->geteffect());}
          } {
            MenuItem {} {
              label {No Effect}
              xywh {10 10 100 20} labelfont 1 labelsize 10
            }
            MenuItem {} {
              label Reverb
              xywh {20 20 100 20} labelfont 1 labelsize 10
            }
            MenuItem {} {
              label Echo
              xywh {30 30 100 20} labelfont 1 labelsize 10
            }
            MenuItem {} {
              label Chorus
              xywh {40 40 100 20} labelfont 1 labelsize 10
            }
            MenuItem {} {
              label Phaser
              xywh {50 50 100 20} labelfont 1 labelsize 10
            }
            MenuItem {} {
              label AlienWah
              xywh {60 60 100 20} labelfont 1 labelsize 10
            }
            MenuItem {} {
              label Distortion
              xywh {70 70 100 20} labelfont 1 labelsize 10
            }
            MenuItem {} {
              label EQ
              xywh {80 80 100 20} labelfont 1 labelsize 10
            }
            MenuItem {} {
              label DynFilter
              xywh {90 90 100 20} labelfont 1 labelsize 10
            }
          }
          Fl_Group syseffectuigroup {open
            xywh {5 203 380 95} color 48
          } {
            Fl_Group syseffectui {
              xywh {5 203 380 95}
              code0 {o->init(master->sysefx[nsyseff]);}
              class EffUI
            } {}
          }
          Fl_Button {} {
            label {Send to...}
            callback {syseffsendwindow->show();}
            xywh {90 181 85 22} box THIN_UP_BOX labelfont 1 labelsize 11
          }
          Fl_Button {} {
            label C
            callback {presetsui->copy(master->sysefx[nsyseff]);}
            xywh {180 187 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 11 labelcolor 55
          }
          Fl_Button {} {
            label P
            callback {pthread_mutex_lock(&master->mutex);
presetsui->paste(master->sysefx[nsyseff],syseffectui);
pthread_mutex_unlock(&master->mutex);}
            xywh {210 187 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 11 labelcolor 55
          }
        }
        Fl_Group {} {
          label {Insertion Effects} open
          xywh {0 165 390 145} labelsize 15 align 9 hide
        } {
          Fl_Counter inseffnocounter {
            label {Ins.Effect No.}
            callback {ninseff=(int) o->value()-1;
insefftype->value(master->insefx[ninseff]->geteffect());
inseffpart->value(master->Pinsparts[ninseff]+2);
inseffectui->refresh(master->insefx[ninseff]);

if (master->Pinsparts[ninseff]!=-1) {
        insefftype->activate();
	inseffectui->activate();
        inseffectuigroup->activate();
} else {
	insefftype->deactivate();
 	inseffectui->deactivate();
        inseffectuigroup->deactivate();
};}
            xywh {5 183 80 22} type Simple labelfont 1 labelsize 10 align 1 minimum 0 maximum 127 step 1 value 1 textfont 1
            code0 {o->bounds(1,NUM_INS_EFX);}
            code1 {o->value(ninseff+1);}
          }
          Fl_Choice insefftype {
            label EffType
            callback {pthread_mutex_lock(&master->mutex);
master->insefx[ninseff]->changeeffect((int) o->value());
pthread_mutex_unlock(&master->mutex);
inseffectui->refresh(master->insefx[ninseff]);
inseffectui->show();}
            xywh {285 173 100 22} down_box BORDER_BOX labelsize 10
            code0 {o->value(master->insefx[ninseff]->geteffect());}
            code1 {if (master->Pinsparts[ninseff]== -1) o->deactivate();}
          } {
            MenuItem {} {
              label {No Effect}
              xywh {25 25 100 20} labelfont 1 labelsize 10
            }
            MenuItem {} {
              label Reverb
              xywh {35 35 100 20} labelfont 1 labelsize 10
            }
            MenuItem {} {
              label Echo
              xywh {45 45 100 20} labelfont 1 labelsize 10
            }
            MenuItem {} {
              label Chorus
              xywh {55 55 100 20} labelfont 1 labelsize 10
            }
            MenuItem {} {
              label Phaser
              xywh {60 60 100 20} labelfont 1 labelsize 10
            }
            MenuItem {} {
              label AlienWah
              xywh {70 70 100 20} labelfont 1 labelsize 10
            }
            MenuItem {} {
              label Distortion
              xywh {80 80 100 20} labelfont 1 labelsize 10
            }
            MenuItem {} {
              label EQ
              xywh {90 90 100 20} labelfont 1 labelsize 10
            }
            MenuItem {} {
              label DynFilter
              xywh {100 100 100 20} labelfont 1 labelsize 10
            }
          }
          Fl_Group inseffectuigroup {open
            xywh {5 205 380 95} box FLAT_BOX color 48
          } {
            Fl_Group inseffectui {
              xywh {5 205 380 90} box UP_FRAME
              code0 {o->init(master->insefx[ninseff]);}
              code1 {if (master->Pinsparts[ninseff]== -1) o->deactivate();}
              class EffUI
            } {}
          }
          Fl_Choice inseffpart {
            label {Insert To.}
            callback {master->Pinsparts[ninseff]=(int) o->value()-2;
if ((int) o->value()==1){
    inseffectuigroup->deactivate();
    insefftype->deactivate();
    inseffectui->deactivate();
} else {
    inseffectuigroup->activate();
    insefftype->activate();
    inseffectui->activate();
};
master->insefx[ninseff]->cleanup();} open
            xywh {95 183 80 22} down_box BORDER_BOX labelfont 1 labelsize 10 align 5 textsize 10
            code0 {o->add("Master Out");o->add("Off");}
            code1 {char tmp[50]; for (int i=0;i<NUM_MIDI_PARTS;i++) {sprintf(tmp,"Part %2d",i+1);o->add(tmp);};}
            code3 {o->value(master->Pinsparts[ninseff]+2);}
          } {}
          Fl_Button {} {
            label C
            callback {presetsui->copy(master->insefx[ninseff]);}
            xywh {180 185 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 11 labelcolor 55
          }
          Fl_Button {} {
            label P
            callback {pthread_mutex_lock(&master->mutex);
presetsui->paste(master->insefx[ninseff],inseffectui);
pthread_mutex_unlock(&master->mutex);}
            xywh {210 185 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 11 labelcolor 55
          }
        }
      }
      Fl_Button {} {
        label Scales
        callback {microtonalui->show();}
        xywh {320 87 65 23} color 51 labelfont 1
      }
      Fl_Group {} {
        xywh {150 40 117 45} box UP_FRAME
      } {
        Fl_Button recordbutton {
          label {Rec.}
          callback {o->deactivate();
recordmenu->deactivate();
recordmenu->label("&Record(*)");
stopbutton->activate();
pausebutton->activate();
pauselabel->activate();
master->HDDRecorder.start();
master->vuresetpeaks();
mastermenu->redraw();}
          tooltip {Start Recording} xywh {159 46 21 21} box ROUND_UP_BOX color 88 labelfont 1 labelsize 10 align 2 deactivate
        }
        Fl_Button stopbutton {
          label Stop
          callback {o->deactivate();
master->HDDRecorder.stop();
recordbutton->deactivate();
pausebutton->deactivate();
pauselabel->deactivate();
recordmenu->activate();
recordmenu->label("&Record");
mastermenu->redraw();}
          tooltip {Stop Recording and close the audio file} xywh {237 46 21 21} box THIN_UP_BOX color 4 labelfont 1 labelsize 10 align 2 deactivate
        }
        Fl_Button pausebutton {
          label {@||}
          callback {o->deactivate();
master->HDDRecorder.pause();
recordbutton->activate();
mastermenu->redraw();}
          tooltip {Pause Recording} xywh {198 46 21 21} box THIN_UP_BOX color 4 selection_color 4 labelfont 1 labelcolor 3 align 16 deactivate
        }
        Fl_Box pauselabel {
          label Pause
          xywh {192 66 30 15} labelfont 1 labelsize 10 deactivate
        }
      }
      Fl_Group {} {open
        xywh {1 490 389 55}
      } {
        Fl_Box {} {
          label {VU-Meter}
          xywh {5 490 380 30} box FLAT_BOX color 48 selection_color 75
          code0 {o->init(master,-1);}
          class VUMeter
        }
      }
      Fl_Check_Button nrpnbutton {
        label NRPN
        callback {master->ctl.NRPN.receive=(int) o->value();}
        tooltip {Receive NRPNs} xywh {10 115 60 25} down_box DOWN_BOX labelsize 12
        code0 {o->value(master->ctl.NRPN.receive);}
      }
      Fl_Counter npartcounter {
        callback {int nval=(int) o->value()-1;
partuigroup->remove(partui);
delete partui;
partui=new PartUI(0,0,765,525);
partuigroup->add(partui);
partui->init(master->part[nval],master,nval,bankui);
partui->redraw();
o->redraw();
npart=nval;

updatepanel();
simplenpartcounter->value(nval+1);
simplenpartcounter->do_callback();}
        tooltip {The part number} xywh {5 312 50 18} type Simple labelfont 1 minimum 0 maximum 127 step 1 value 1 textfont 1
        code0 {o->bounds(1,NUM_MIDI_PARTS);}
        code1 {bankui->init(o);}
      }
      Fl_Button {} {
        label vK
        callback {virkeyboard->show();}
        tooltip {Virtual Keyboard} xywh {280 87 40 23} color 51 labelfont 1
      }
      Fl_Group {} {open
        xywh {85 32 55 110} box UP_FRAME
      } {
        Fl_Button {} {
          label Reset
          callback {globalfinedetuneslider->value(64.0);
globalfinedetuneslider->do_callback();}
          tooltip {Master fine detune reset} xywh {90 37 45 23} box THIN_UP_BOX labelsize 10
        }
        Fl_Dial globalfinedetuneslider {
          label {Fine Detune}
          callback {master->microtonal.Pglobalfinedetune=(int) o->value();}
          tooltip {global fine detune} xywh {90 68 45 45} box ROUND_UP_BOX labelsize 9 align 130 maximum 127 step 1 value 64
          code0 {o->value(master->microtonal.Pglobalfinedetune);}
          class WidgetPDial
        }
      }
      Fl_Button {} {
        label {Panel Window}
        callback {updatepanel();
panelwindow->show();}
        tooltip {Panel Window} xywh {280 112 105 23} color 51 labelfont 1 labelsize 10
      }
      Fl_Button sm_indicator1 {
        label SM
        xywh {350 5 35 15} box ROUNDED_BOX down_box ROUNDED_BOX color 45 selection_color 93 labelfont 3 labelcolor 39 deactivate
      }
    }
    Fl_Window aboutwindow {
      label {Copyright...}
      xywh {411 344 365 280} type Double hide
    } {
      Fl_Box {} {
        label {Copyright (c) 2002-2009 Nasca O. PAUL and others. Please read AUTHORS.txt}
        xywh {15 35 335 55} labeltype EMBOSSED_LABEL labelsize 15 align 208
      }
      Fl_Box {} {
        label {This is free software; you may redistribute it and/or modify it under the terms of the 
version 2 (or any later version) of the GNU General Public License as published by the Free Software Fundation.
  This program comes with
 ABSOLUTELY NO WARRANTY. 
 See the version 2 (or any later version) of the 
GNU General Public License for details.}
        xywh {15 90 335 145} labelfont 1 labelsize 11 align 144
      }
      Fl_Button {} {
        label {Close this window}
        callback {aboutwindow->hide();}
        xywh {80 245 190 25} box THIN_UP_BOX labelsize 11
      }
      Fl_Box {} {
        label ZynAddSubFX
        xywh {15 5 335 30} labeltype EMBOSSED_LABEL labelfont 1 labelsize 20 align 16
      }
    }
    Fl_Window syseffsendwindow {
      label {System Effects Send}
      xywh {171 234 120 250} type Double hide resizable
    } {
      Fl_Scroll {} {open
        xywh {0 45 120 170} box FLAT_BOX resizable
        code0 {for (int neff1=0;neff1<NUM_SYS_EFX;neff1++) for (int neff2=neff1+1;neff2<NUM_SYS_EFX;neff2++)}
        code1 {{syseffsend[neff1][neff2]=new SysEffSend(o->x()+(neff2-1)*35,o->y()+15+neff1*50,30,30);syseffsend[neff1][neff2]->label("aaa");syseffsend[neff1][neff2]->init(master,neff1,neff2);};}
      } {}
      Fl_Button {} {
        label Close
        callback {syseffsendwindow->hide();}
        xywh {25 220 80 25} box THIN_UP_BOX
      }
      Fl_Box {} {
        label {Send system effect's output to other system effects}
        xywh {5 5 110 35} labelsize 10 align 192
      }
    }
    Fl_Window panelwindow {
      label {ZynAddSubFX Panel}
      xywh {89 59 630 635} type Double hide
    } {
      Fl_Scroll {} {
        xywh {0 5 570 310} type HORIZONTAL box THIN_UP_BOX
      } {
        Fl_Pack {} {
          xywh {5 10 560 285} type HORIZONTAL
          code0 {for (int i=0;i<NUM_MIDI_PARTS/2;i++){panellistitem[i]=new Panellistitem(0,0,70,260,"");panellistitem[i]->init(master,i,bankui);}}
        } {}
      }
      Fl_Scroll {} {
        xywh {0 320 570 310} type HORIZONTAL box THIN_UP_BOX
      } {
        Fl_Pack {} {
          xywh {5 325 560 285} type HORIZONTAL
          code0 {for (int i=NUM_MIDI_PARTS/2;i<NUM_MIDI_PARTS;i++){panellistitem[i]=new Panellistitem(0,0,70,260,"");panellistitem[i]->init(master,i,bankui);}}
        } {}
      }
      Fl_Button {} {
        label Close
        callback {panelwindow->hide();
updatepanel();}
        xywh {575 605 50 25} box THIN_UP_BOX labelsize 13
      }
      Fl_Button {} {
        label Refresh
        callback {updatepanel();}
        xywh {575 570 55 25} box THIN_UP_BOX labelsize 13
      }
    }
    Fl_Window simplemasterwindow {
      label ZynAddSubFX
      callback {\#ifndef PLUGINVERSION
if (fl_choice("Exit and leave the unsaved data?","No","Yes",NULL))
\#endif
{
	config.save();
	*exitprogram=1;
};
} open
      xywh {283 262 600 335} type Double visible
    } {
      Fl_Menu_Bar simplemastermenu {
        xywh {0 0 690 25}
      } {
        Submenu {} {
          label {&File}
          xywh {10 10 100 20}
        } {
          MenuItem {} {
            label {&New (erase all)...}
            callback {do_new_master();}
            xywh {30 30 100 20}
          }
          MenuItem {} {
            label {&Open Parameters...}
            callback {do_load_master();}
            xywh {30 30 100 20}
          }
          MenuItem {} {
            label {&Save All Parameters...}
            callback {\#if USE_NSM
            if ( nsm && nsm->is_active() )
            {
                do_save_master( nsm->project_filename );
            }
            else
\#endif
            {
                 do_save_master();
            }}
            xywh {20 20 100 20} divider
          }
          MenuItem {} {
            label {&Settings...}
            callback {configui->show();}
            xywh {35 35 100 20} divider
          }
          MenuItem {} {
            label {&Copyright...}
            callback {aboutwindow->show();}
            xywh {25 25 100 20} divider
          }
          MenuItem {} {
            label {E&xit}
            callback {masterwindow->do_callback();}
            xywh {20 20 100 20}
          }
        }
        Submenu {} {
          label {&Instrument}
          xywh {20 20 100 20}
        } {
          MenuItem {} {
            label {&Open Instrument...}
            callback {const char *filename;
filename=fl_file_chooser("Load:","({*.xiz})",NULL,0);
if (filename==NULL) return;


pthread_mutex_lock(&master->mutex);
//  int npart=(int)npartcounter->value()-1;

  //clear all instrument parameters, first
  master->part[npart]->defaultsinstrument();

  //load the instr. parameters
  int result=master->part[npart]->loadXMLinstrument(filename);

pthread_mutex_unlock(&master->mutex);
master->part[npart]->applyparameters();

simplenpartcounter->do_callback();

if (result==-10) fl_alert("Error: Could not load the file\\nbecause it is not an instrument file.");
      else if (result<0) fl_alert("Error: Could not load the file.");}
            xywh {40 40 100 20}
          }
          MenuItem {} {
            label {Show Instrument &Bank...}
            callback {bankui->show();}
            xywh {10 10 100 20} divider
          }
        }
        Submenu {} {
          label Misc
          xywh {0 0 100 20}
        } {
          MenuItem {} {
            label {Switch User Interface Mode}
            callback {if (fl_choice("Switch the User Interface to Advanced mode ?","No","Yes",NULL)){
	simplemasterwindow->hide();
	refresh_master_ui();
	masterwindow->show();
	config.cfg.UserInterfaceMode=1;
};}
            xywh {0 0 100 20}
          }
        }
      }
      Fl_Group simplelistitemgroup {open
        private xywh {125 65 215 145} box UP_FRAME
        code0 {if (master->part[npart]->Penabled==0) o->deactivate();}
      } {
        Fl_Button partname {
          callback {if ((int)bankui->cbwig->value()!=(npart+1)){
   bankui->cbwig->value(npart+1);
   bankui->cbwig->do_callback();
};
bankui->show();}
          xywh {130 72 205 18} box THIN_DOWN_BOX down_box FLAT_BOX color 50 labelfont 1 labelsize 11 align 208
        }
        Fl_Slider partpanning {
          label Pan
          callback {master->part[npart]->setPpanning((int) o->value());}
          xywh {185 95 145 15} type {Horz Knob} box FLAT_BOX labelsize 11 maximum 127 step 1 value 64
          code0 {o->value(master->part[npart]->Ppanning);}
        }
        Fl_Choice partrcv {
          label {Midi Channel Receive}
          callback {virkeys->relaseallkeys(0);
master->part[npart]->Prcvchn=(int) o->value();
virkeys->midich=(int) o->value();} open
          tooltip {receive from Midi channel} xywh {140 157 65 18} down_box BORDER_BOX labelsize 10 align 130 textfont 1
          code0 {char nrstr[10]; for(int i=0;i<NUM_MIDI_CHANNELS;i++){sprintf(nrstr,"Ch%d",i+1);if (i!=9) o->add(nrstr); else o->add("Dr10");};}
          code1 {o->value(master->part[npart]->Prcvchn);}
        } {}
        Fl_Dial partvolume {
          callback {master->part[npart]->setPvolume((int) o->value());}
          xywh {135 95 45 40} labelsize 9 maximum 127 step 1
          code0 {o->value(master->part[npart]->Pvolume);}
          class WidgetPDial
        }
        Fl_Box {} {
          label Volume
          xywh {130 130 55 20} labelsize 10
        }
        Fl_Check_Button simplepartportamento {
          label Portamento
          callback {master->part[npart]->ctl.portamento.portamento=(int) o->value();}
          tooltip {Enable/Disable the portamento} xywh {193 127 79 23} down_box DOWN_BOX labelsize 9
          code0 {o->value(master->part[npart]->ctl.portamento.portamento);}
        }
        Fl_Counter simpleminkcounter {
          label {Min.key}
          callback {master->part[npart]->Pminkey=(int) o->value();
if (master->part[npart]->Pminkey>master->part[npart]->Pmaxkey) o->textcolor(FL_RED);
 else o->textcolor(FL_BLACK);}
          tooltip {Minimum key (that the part receives NoteOn messages)} xywh {210 158 40 15} type Simple labelsize 10 minimum 0 maximum 127 step 1 textsize 10
          code0 {o->value(master->part[npart]->Pminkey);}
        }
        Fl_Counter simplemaxkcounter {
          label {Max.key}
          callback {master->part[npart]->Pmaxkey=(int) o->value();

if (master->part[npart]->Pminkey>master->part[npart]->Pmaxkey) o->textcolor(FL_RED);
 else o->textcolor(FL_BLACK);}
          tooltip {Maximum key (that the part receives NoteOn messages)} xywh {255 158 40 15} type Simple labelsize 10 minimum 0 maximum 127 step 1 textsize 10
          code0 {o->value(master->part[npart]->Pmaxkey);}
        }
        Fl_Button {} {
          label m
          callback {if (master->part[npart]->lastnote>=0) simpleminkcounter->value(master->part[npart]->lastnote);
simpleminkcounter->do_callback();
simplemaxkcounter->do_callback();}
          tooltip {set the minimum key to the last pressed key} xywh {230 188 15 12} box THIN_UP_BOX labelsize 10
        }
        Fl_Button {} {
          label M
          callback {if (master->part[npart]->lastnote>=0) simplemaxkcounter->value(master->part[npart]->lastnote);
simplemaxkcounter->do_callback();
simpleminkcounter->do_callback();}
          tooltip {set the maximum key to the last pressed key} xywh {260 188 15 12} box THIN_UP_BOX labelsize 10
        }
        Fl_Button {} {
          label R
          callback {simpleminkcounter->value(0);
simpleminkcounter->do_callback();
simplemaxkcounter->value(127);
simplemaxkcounter->do_callback();}
          tooltip {reset the minimum key to 0 and maximum key to 127} xywh {245 188 15 12} box THIN_UP_BOX labelfont 1 labelsize 10
        }
        Fl_Counter simplepartkeyshiftcounter {
          label KeyShift
          callback {master->part[npart]->Pkeyshift=(int) o->value()+64;}
          xywh {280 120 50 20} type Simple labelsize 11 minimum -64 maximum 64 step 1
          code0 {o->lstep(12);}
          code1 {o->value(master->part[npart]->Pkeyshift-64);}
        }
        Fl_Dial simplesyseffsend {
          callback {master->setPsysefxvol(npart,nsyseff,(int) o->value());}
          xywh {300 160 30 30} maximum 127 step 1
          class WidgetPDial
        }
        Fl_Box {} {
          label Effect
          xywh {295 190 40 15} labelsize 10
        }
      }
      Fl_Check_Button partenabled {
        label Enabled
        callback {pthread_mutex_lock(&master->mutex);
 master->partonoff(npart,(int) o->value());
pthread_mutex_unlock(&master->mutex);

if ((int) o->value()==0) simplelistitemgroup->deactivate();
  else {
    simplelistitemgroup->activate();
    if ((int)bankui->cbwig->value()!=(npart+1)){
       bankui->cbwig->value(npart+1);
       bankui->cbwig->do_callback();
    };
};

o->redraw();}
        private xywh {250 40 85 20} down_box DOWN_BOX labeltype EMBOSSED_LABEL labelfont 1 labelsize 13 align 24
        code0 {//char tmp[10];snprintf(tmp,10,"%d",npart+1);o->copy_label(tmp);}
        code1 {o->value(master->part[npart]->Penabled);}
      }
      Fl_Box virkeys {
        label Keyboard
        xywh {5 215 590 80} box BORDER_BOX color 17
        code0 {o->init(master);}
        class VirKeys
      }
      Fl_Group {} {open
        xywh {340 30 255 185}
      } {
        Fl_Tabs {} {open
          xywh {345 35 245 175} box UP_FRAME align 18
        } {
          Fl_Group {} {
            label {System Effects} open
            xywh {345 55 245 155} box UP_FRAME labelfont 1 labelsize 12 align 18
          } {
            Fl_Counter simplesyseffnocounter {
              label {Sys.Effect No.}
              callback {nsyseff=(int) o->value()-1;
simplesysefftype->value(master->sysefx[nsyseff]->geteffect());
simplesyseffectui->refresh(master->sysefx[nsyseff]);
simplerefresh();}
              xywh {350 75 80 20} type Simple labelfont 1 labelsize 10 align 1 minimum 0 maximum 127 step 1 value 1 textfont 1
              code0 {o->bounds(1,NUM_SYS_EFX);}
              code1 {o->value(nsyseff+1);}
            }
            Fl_Choice simplesysefftype {
              label EffType
              callback {pthread_mutex_lock(&master->mutex);
master->sysefx[nsyseff]->changeeffect((int) o->value());
pthread_mutex_unlock(&master->mutex);
simplesyseffectui->refresh(master->sysefx[nsyseff]);}
              xywh {515 80 70 15} down_box BORDER_BOX labelsize 10 align 5
              code0 {o->value(master->sysefx[nsyseff]->geteffect());}
            } {
              MenuItem {} {
                label {No Effect}
                xywh {20 20 100 20} labelfont 1 labelsize 10
              }
              MenuItem {} {
                label Reverb
                xywh {30 30 100 20} labelfont 1 labelsize 10
              }
              MenuItem {} {
                label Echo
                xywh {40 40 100 20} labelfont 1 labelsize 10
              }
              MenuItem {} {
                label Chorus
                xywh {50 50 100 20} labelfont 1 labelsize 10
              }
              MenuItem {} {
                label Phaser
                xywh {60 60 100 20} labelfont 1 labelsize 10
              }
              MenuItem {} {
                label AlienWah
                xywh {70 70 100 20} labelfont 1 labelsize 10
              }
              MenuItem {} {
                label Distortion
                xywh {80 80 100 20} labelfont 1 labelsize 10
              }
              MenuItem {} {
                label EQ
                xywh {90 90 100 20} labelfont 1 labelsize 10
              }
              MenuItem {} {
                label DynFilter
                xywh {100 100 100 20} labelfont 1 labelsize 10
              }
            }
            Fl_Group simplesyseffectuigroup {open
              xywh {350 95 235 95} color 48
            } {
              Fl_Group simplesyseffectui {
                xywh {350 95 234 95}
                code0 {o->init(master->sysefx[nsyseff]);}
                class SimpleEffUI
              } {}
            }
            Fl_Button {} {
              label {Send to...}
              callback {syseffsendwindow->show();}
              xywh {435 75 75 20} box THIN_UP_BOX labelfont 1 labelsize 11
            }
            Fl_Button {} {
              label P
              callback {pthread_mutex_lock(&master->mutex);
presetsui->paste(master->sysefx[nsyseff],simplesyseffectui);
pthread_mutex_unlock(&master->mutex);}
              xywh {560 65 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 11 labelcolor 55
            }
          }
          Fl_Group {} {
            label {Insertion Effects}
            xywh {345 55 245 155} box UP_FRAME labelfont 1 labelsize 12 align 18 hide
          } {
            Fl_Counter simpleinseffnocounter {
              label {Ins.Effect No.}
              callback {ninseff=(int) o->value()-1;
simpleinsefftype->value(master->insefx[ninseff]->geteffect());
simpleinseffpart->value(master->Pinsparts[ninseff]+2);
simpleinseffectui->refresh(master->insefx[ninseff]);

if (master->Pinsparts[ninseff]!=-1) {
        simpleinsefftype->activate();
	simpleinseffectui->activate();
        simpleinseffectuigroup->activate();
} else {
	simpleinsefftype->deactivate();
 	simpleinseffectui->deactivate();
        simpleinseffectuigroup->deactivate();
};}
              xywh {350 75 80 20} type Simple labelfont 1 labelsize 10 align 1 minimum 0 maximum 127 step 1 value 1 textfont 1
              code0 {o->bounds(1,NUM_INS_EFX);}
              code1 {o->value(ninseff+1);}
            }
            Fl_Choice simpleinsefftype {
              label EffType
              callback {pthread_mutex_lock(&master->mutex);
master->insefx[ninseff]->changeeffect((int) o->value());
pthread_mutex_unlock(&master->mutex);
simpleinseffectui->refresh(master->insefx[ninseff]);
simpleinseffectui->show();}
              xywh {515 80 70 15} down_box BORDER_BOX labelsize 10 align 5
              code0 {o->value(master->insefx[ninseff]->geteffect());}
              code1 {if (master->Pinsparts[ninseff]== -1) o->deactivate();}
            } {
              MenuItem {} {
                label {No Effect}
                xywh {35 35 100 20} labelfont 1 labelsize 10
              }
              MenuItem {} {
                label Reverb
                xywh {45 45 100 20} labelfont 1 labelsize 10
              }
              MenuItem {} {
                label Echo
                xywh {55 55 100 20} labelfont 1 labelsize 10
              }
              MenuItem {} {
                label Chorus
                xywh {65 65 100 20} labelfont 1 labelsize 10
              }
              MenuItem {} {
                label Phaser
                xywh {70 70 100 20} labelfont 1 labelsize 10
              }
              MenuItem {} {
                label AlienWah
                xywh {80 80 100 20} labelfont 1 labelsize 10
              }
              MenuItem {} {
                label Distortion
                xywh {90 90 100 20} labelfont 1 labelsize 10
              }
              MenuItem {} {
                label EQ
                xywh {100 100 100 20} labelfont 1 labelsize 10
              }
              MenuItem {} {
                label DynFilter
                xywh {110 110 100 20} labelfont 1 labelsize 10
              }
            }
            Fl_Group simpleinseffectuigroup {
              xywh {350 95 234 95} box FLAT_BOX color 48
            } {
              Fl_Group simpleinseffectui {
                xywh {350 95 234 95}
                code0 {o->init(master->insefx[ninseff]);}
                code1 {if (master->Pinsparts[ninseff]== -1) o->deactivate();}
                class SimpleEffUI
              } {}
            }
            Fl_Choice simpleinseffpart {
              label {Insert To.}
              callback {master->Pinsparts[ninseff]=(int) o->value()-2;
if ((int) o->value()==1){
    simpleinseffectuigroup->deactivate();
    simpleinsefftype->deactivate();
    simpleinseffectui->deactivate();
} else {
    simpleinseffectuigroup->activate();
    simpleinsefftype->activate();
    simpleinseffectui->activate();
};
master->insefx[ninseff]->cleanup();} open
              xywh {435 75 80 20} down_box BORDER_BOX labelfont 1 labelsize 10 align 5 textsize 10
              code0 {o->add("Master Out");o->add("Off");}
              code1 {char tmp[50]; for (int i=0;i<NUM_MIDI_PARTS;i++) {sprintf(tmp,"Part %2d",i+1);o->add(tmp);};}
              code3 {o->value(master->Pinsparts[ninseff]+2);}
            } {}
            Fl_Button {} {
              label P
              callback {pthread_mutex_lock(&master->mutex);
presetsui->paste(master->insefx[ninseff],simpleinseffectui);
pthread_mutex_unlock(&master->mutex);}
              xywh {560 65 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 11 labelcolor 55
            }
          }
        }
      }
      Fl_Group {} {open
        xywh {5 300 590 30} box ENGRAVED_FRAME
      } {
        Fl_Box {} {
          label {VU-Meter}
          xywh {5 300 590 30} box FLAT_BOX color 41 selection_color 75
          code0 {o->init(master,-1);}
          class VUMeter
        }
      }
      Fl_Dial simplemastervolumedial {
        label {Master Volume}
        callback {master->setPvolume((int) o->value());}
        tooltip {Master Volume} xywh {10 35 40 40} box ROUND_UP_BOX labelfont 1 labelsize 11 align 130 maximum 127 step 1
        code0 {o->value(master->Pvolume);}
        class WidgetPDial
      }
      Fl_Counter simplemasterkeyshiftcounter {
        label {Master KeyShift}
        callback {master->setPkeyshift((int) o->value()+64);}
        xywh {15 110 90 20} labelsize 11 minimum -64 maximum 64 step 1
        code0 {o->lstep(12);}
        code1 {o->value(master->Pkeyshift-64);}
      }
      Fl_Button {} {
        label {Stop ALL sounds!}
        callback {virkeyboard->relaseallkeys();
pthread_mutex_lock(&master->mutex);
master->shutup=1;
pthread_mutex_unlock(&master->mutex);}
        xywh {5 149 115 31} color 90 labelfont 1 labelsize 10
      }
      Fl_Button {} {
        label Reset
        callback {simpleglobalfinedetuneslider->value(64.0);
simpleglobalfinedetuneslider->do_callback();}
        tooltip {Master fine detune reset} xywh {70 30 50 17} box THIN_UP_BOX labelsize 11 align 128
      }
      Fl_Dial simpleglobalfinedetuneslider {
        label {Fine Detune}
        callback {master->microtonal.Pglobalfinedetune=(int) o->value();}
        tooltip {global fine detune} xywh {80 50 30 30} box ROUND_UP_BOX labelsize 11 align 130 maximum 127 step 1 value 64
        code0 {o->value(master->microtonal.Pglobalfinedetune);}
        class WidgetPDial
      }
      Fl_Counter simplenpartcounter {
        label Part
        callback {virkeys->relaseallkeys(0);
npartcounter->value(o->value());
npart=(int) o->value()-1;

simplerefresh();
virkeys->midich=master->part[npart]->Prcvchn;}
        tooltip {The part number} xywh {170 40 70 20} type Simple labelfont 1 align 4 minimum 0 maximum 127 step 1 value 1 textfont 1
        code0 {o->bounds(1,NUM_MIDI_PARTS);}
      }
      Fl_Counter {} {
        label {Keyb.Oct.}
        callback {virkeys->relaseallkeys(0);
virkeys->midioct=(int) o->value();
virkeys->take_focus();}
        tooltip {Midi Octave} xywh {5 190 55 20} type Simple labelsize 11 align 8 when 6 minimum 0 maximum 5 step 1 textfont 1 textsize 11
        code0 {o->value(virkeys->midioct);}
      }
      Fl_Button sm_indicator2 {
        label SM
        xywh {560 5 35 15} box ROUNDED_BOX down_box ROUNDED_BOX color 45 selection_color 93 labelfont 3 labelcolor 39 deactivate
      }
    }
    Fl_Window selectuiwindow {
      label {User Interface mode}
      callback {*exitprogram=1;}
      xywh {342 246 430 250} type Double hide non_modal
    } {
      Fl_Box {} {
        label {Welcome to ZynAddSubFX}
        xywh {5 5 425 40} labeltype SHADOW_LABEL labelfont 1 labelsize 26
      }
      Fl_Box {} {
        label {Please choose the interface mode:}
        xywh {10 50 265 25} labelfont 1 labelsize 13
      }
      Fl_Button {} {
        label Advanced
        callback {config.cfg.UserInterfaceMode=1;
masterwindow->show();
selectuiwindow->hide();}
        xywh {10 165 100 35} color 229 labelfont 1 labelsize 16
      }
      Fl_Box {} {
        label {.. if you have used ZynAddSubFX before, or you like to have full controll to all parameters.}
        xywh {110 165 310 35} labelfont 1 labelsize 11 align 144
      }
      Fl_Button {} {
        label Beginner
        callback {simplemasterwindow->show();
selectuiwindow->hide();
config.cfg.UserInterfaceMode=2;}
        xywh {10 80 100 65} color 238 labelfont 1 labelsize 16
      }
      Fl_Box {} {
        label {..if you are a beginner, you prefer using presets or you prefer to use simpler user interfaces. Most functionality of ZynAddSubFX will be hidden in this mode to make simple the learning/using it.}
        xywh {110 75 320 75} labelfont 1 labelsize 11 align 144
      }
      Fl_Box {} {
        label {You can switch the interface modes anytime you want.}
        xywh {30 215 360 25} box BORDER_BOX color 51 labelfont 1 labelsize 11 align 144
      }
    }
  }
  Function {updatesendwindow()} {} {
    code {for (int neff1=0;neff1<NUM_SYS_EFX;neff1++) 
  for (int neff2=neff1+1;neff2<NUM_SYS_EFX;neff2++)
    syseffsend[neff1][neff2]->value(master->Psysefxsend[neff1][neff2]);} {}
  }
  Function {updatepanel()} {} {
    code {for (int npart=0;npart<NUM_MIDI_PARTS;npart++){
  panellistitem[npart]->refresh();
};} {}
  }
  Function {setfilelabel(const char *filename)} {} {
    code {if (filename!=NULL) snprintf(&masterwindowlabel[0],100,"%s - ZynAddSubFX",fl_filename_name(filename));
  else snprintf(&masterwindowlabel[0],100,"%s","ZynAddSubFX");
masterwindowlabel[99]='\\0';
masterwindow->label(&masterwindowlabel[0]);
simplemasterwindow->label(&masterwindowlabel[0]);} {}
  }
  Function {MasterUI(Master *master_,int *exitprogram_)} {} {
    code {master=master_;
exitprogram=exitprogram_;
ninseff=0;
nsyseff=0;
npart=0;

for (int i=0;i<NUM_SYS_EFX;i++)
   for (int j=0;j<NUM_SYS_EFX;j++)
     syseffsend[i][j]=NULL;

microtonalui=new MicrotonalUI(&master->microtonal);
virkeyboard=new VirKeyboard(master);
bankui=new BankUI(master,&npart);
configui=new ConfigUI();

make_window();
\#ifdef OS_WINDOWS
masterwindow->icon((char *)LoadIcon(GetModuleHandle(NULL), "zynaddsubfx_icon"));
\#endif

presetsui=new PresetsUI();
setfilelabel(NULL);
swapefftype=0;
simplerefresh();} {}
  }
  Function {~MasterUI()} {} {
    code {masterwindow->hide();
delete masterwindow;
simplemasterwindow->hide();
delete simplemasterwindow;
aboutwindow->hide();
delete aboutwindow;
syseffsendwindow->hide();
delete syseffsendwindow;

delete virkeyboard;
delete microtonalui;
delete bankui;
delete configui;

delete presetsui;
delete panelwindow;
delete selectuiwindow;} {}
  }
  Function {showUI()} {} {
    code {switch (config.cfg.UserInterfaceMode){
	case 0:selectuiwindow->show();
	break;
	case 1:masterwindow->show();
	break;
	case 2:simplemasterwindow->show();
	break;
};} {}
  }
  Function {simplerefresh()} {} {
    code {partenabled->value(master->part[npart]->Penabled);
if (master->part[npart]->Penabled!=0) simplelistitemgroup->activate();
     else simplelistitemgroup->deactivate();

partvolume->value(master->part[npart]->Pvolume);
partpanning->value(master->part[npart]->Ppanning);
partrcv->value(master->part[npart]->Prcvchn);

if (master->part[npart]->Pname[0]!=0) partname->label((char *)master->part[npart]->Pname);
	else partname->label("Click here to load a instrument");

simplelistitemgroup->redraw();
simplepartportamento->value(master->part[npart]->ctl.portamento.portamento);
simpleminkcounter->value(master->part[npart]->Pminkey);
simplemaxkcounter->value(master->part[npart]->Pmaxkey);

simplepartkeyshiftcounter->value(master->part[npart]->Pkeyshift-64);
simplesyseffsend->value(master->Psysefxvol[nsyseff][npart]);} {}
  }
  Function {do_new_master_unconditional()} {} {
    code {delete microtonalui;

       pthread_mutex_lock(&master->mutex);
	master->defaults();
       pthread_mutex_unlock(&master->mutex);
	
       npartcounter->value(1);
       refresh_master_ui();
       updatepanel();} {}
  }
  Function {do_new_master()} {} {
    code {if (fl_choice("Clear *ALL* the parameters ?","No","Yes",NULL)){
         do_new_master_unconditional();
         }} {}
  }
  Function {do_load_master_unconditional(const char *filename, const char *display_name)} {return_type int
  } {
    code {pthread_mutex_lock(&master->mutex);
    //clear all parameters
    master->defaults();
    
    //load the data
    int result=master->loadXML(filename);
    
    master->applyparameters(false);
    pthread_mutex_unlock(&master->mutex);
    
    npartcounter->value(1);
    refresh_master_ui();
    updatepanel();

    if (result>=0) setfilelabel(display_name);
    
    return result;} {}
  }
  Function {do_load_master(const char* file = NULL)} {} {
    code {const char *filename;
  if (file == NULL) {
    filename=fl_file_chooser("Open:","({*.xmz})",NULL,0);
    if (filename==NULL) return;
  }
  else {
    filename = file;
  }

  int result = do_load_master_unconditional( filename, filename );

if (result==-10) fl_alert("Error: Could not load the file\\nbecause it is not a zynaddsubfx parameters file.");
      else if (result<0) fl_alert("Error: Could not load the file.");} {}
  }
  Function {do_save_master(const char* file = NULL)} {} {
    code {const char *filename;
char *tmp;
  int result=0;
  if (file == NULL) {
    tmp=fl_file_chooser("Save:","({*.xmz})",NULL,0);
    if (tmp==NULL) return;
    tmp=fl_filename_setext(tmp,".xmz");
    filename=tmp;
    result=fileexists(tmp);
    if (result) {
      result=0;
      if (!fl_choice("The file exists. Overwrite it?","No","Yes",NULL)) return;
      
    }
  }
  else {
    filename = file;
  }


pthread_mutex_lock(&master->mutex);
result=master->saveXML(filename);
pthread_mutex_unlock(&master->mutex);

if (result<0) fl_alert("Error: Could not save the file.");
	else
{
\#if USE_NSM
        if ( nsm && nsm->is_active() )
             setfilelabel( nsm->display_name );
        else
\#endif
             setfilelabel(filename);
}
updatepanel();} {}
  }
  Function {refresh_master_ui()} {} {
    code {ninseff=0;
nsyseff=0;
npart=0;

//the Master UI
npartcounter->do_callback();
syseffnocounter->do_callback();
inseffnocounter->do_callback();
masterkeyshiftcounter->value(master->Pkeyshift-64);
mastervolumedial->value(master->Pvolume);    
globalfinedetuneslider->value(master->microtonal.Pglobalfinedetune);   
microtonalui=new MicrotonalUI(&master->microtonal);
nrpnbutton->value(master->ctl.NRPN.receive);
updatesendwindow();
updatepanel();

//the simle MasterUI
simplenpartcounter->value(1);
simplesyseffnocounter->value(1);
simpleinseffnocounter->value(1);
simplenpartcounter->do_callback();
simplesyseffnocounter->do_callback();
simpleinseffnocounter->do_callback();
simplemasterkeyshiftcounter->value(master->Pkeyshift-64);
simplemastervolumedial->value(master->Pvolume);    
simpleglobalfinedetuneslider->value(master->microtonal.Pglobalfinedetune);
virkeys->midich=master->part[npart]->Prcvchn;

simplerefresh();
bankui->hide();} {}
  }
  decl {Master *master;} {}
  decl {MicrotonalUI *microtonalui;} {}
  decl {BankUI *bankui;} {}
  decl {int ninseff,npart;} {}
  decl {int nsyseff;} {}
  decl {int *exitprogram;} {}
  decl {SysEffSend *syseffsend[NUM_SYS_EFX][NUM_SYS_EFX];} {}
  decl {VirKeyboard *virkeyboard;} {}
  decl {ConfigUI *configui;} {}
  decl {int swapefftype;} {}
  decl {char masterwindowlabel[100];} {}
  decl {Panellistitem *panellistitem[NUM_MIDI_PARTS];} {}
  decl {NioUI nioui;} {}
} 
